package com.ruoyi.production.service.impl.regulator;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.production.mapper.regulator.RegulatorAmountMapper;
import com.ruoyi.production.domain.regulator.RegulatorAmount;
import com.ruoyi.production.service.regulator.IRegulatorAmountService;

/**
 * 调节剂量Service业务层处理
 *
 * @author ruoyi
 * @date 2021-07-12
 */
@Service
public class RegulatorAmountServiceImpl implements IRegulatorAmountService
{
    @Autowired
    private RegulatorAmountMapper regulatorAmountMapper;

    /**
     * 查询调节剂量
     *
     * @param regulatorAmountId 调节剂量ID
     * @return 调节剂量
     */
    @Override
    public RegulatorAmount selectRegulatorAmountById(Long regulatorAmountId)
    {
        return regulatorAmountMapper.selectRegulatorAmountById(regulatorAmountId);
    }

    /**
     * 查询调节剂量列表
     *
     * @param regulatorAmount 调节剂量
     * @return 调节剂量
     */
    @Override
    public List<RegulatorAmount> selectRegulatorAmountList(RegulatorAmount regulatorAmount)
    {
        return regulatorAmountMapper.selectRegulatorAmountList(regulatorAmount);
    }

    /**
     * 新增调节剂量
     *
     * @param regulatorAmount 调节剂量
     * @return 结果
     */
    @Override
    public int insertRegulatorAmount(RegulatorAmount regulatorAmount)
    {
        regulatorAmount.setCreateTime(DateUtils.getNowDate());
//        向已有的数据直接在原来的基础上添加库存
        int r =regulatorAmountMapper.updateRegulatorAmount1(regulatorAmount);
        if(r==0) {
            //        若原来的上面没有，则新加数据
            return regulatorAmountMapper.insertRegulatorAmount(regulatorAmount);
        }
        return 1;
    }

    /**
     * 修改调节剂量
     *
     * @param regulatorAmount 调节剂量
     * @return 结果
     */
    @Override
    public int updateRegulatorAmount(RegulatorAmount regulatorAmount)
    {
        regulatorAmount.setUpdateTime(DateUtils.getNowDate());
        //        删除这条数据，将这条数据当作新数据处理
        regulatorAmountMapper.deleteRegulatorAmountById(regulatorAmount.getRegulatorAmountId());
        //        若原来已有的数据，则向已有的数据直接在原来的基础上添加库存
        int r =regulatorAmountMapper.updateRegulatorAmount1(regulatorAmount);
        if(r==0){
            //        若原来的上面没有，则当作新数据插入
            return regulatorAmountMapper.insertRegulatorAmount(regulatorAmount);
        }
        return 1;
    }

    /**
     * 批量删除调节剂量
     *
     * @param regulatorAmountIds 需要删除的调节剂量ID
     * @return 结果
     */
    @Override
    public int deleteRegulatorAmountByIds(Long[] regulatorAmountIds)
    {
        return regulatorAmountMapper.deleteRegulatorAmountByIds(regulatorAmountIds);
    }

    /**
     * 删除调节剂量信息
     *
     * @param regulatorAmountId 调节剂量ID
     * @return 结果
     */
    @Override
    public int deleteRegulatorAmountById(Long regulatorAmountId)
    {
        return regulatorAmountMapper.deleteRegulatorAmountById(regulatorAmountId);
    }
}
